package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.AttrModifyHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.BandwidthBusinessModelHandler;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.CircuitTypeHandler;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.SuddenCycleHandler;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.iwhalecloud.bss.kite.event.attr.UpdateAttrValueEvent;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * @author 付喆
 * @version 2021/5/25 19:55
 * Description:
 */
@Service
@AttrHandler(CircuitTypeHandler.class)
@AttrHandler(BandwidthBusinessModelHandler.class)
public class SuddenBandwidthLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void handle(KiteAttr kiteAttr, KiteInst kiteInst, AttrData attrData) {
        // 承载电路类型
        if(KiteStringUtils.isEmpty(kiteInst.getAttrValue("210004190"))){
            return;
        }
        // 如果是数字电路
        if(KiteStringUtils.equals(kiteInst.getAttrValue("210004190"), "1_0000229")){
            LocalAttrHelper.hideAndNullable(kiteInst,
                //不显示 突发带宽属性、突发周期属性、突发开始时间属性、突发结束时间
                "210004191", "200001824", "210004306", "210004307");
            LocalAttrHelper.hideAndNullable(kiteInst, "210004194", "210004195");
            // 如果是以太网电路
        }else if(KiteStringUtils.equals(kiteInst.getAttrValue("210004190"), "110007436")){
            // 带宽业务模式
            if(KiteStringUtils.isEmpty(kiteInst.getAttrValue("210004221"))){
                return;
            }
            // 如果不是可变带宽（固定带宽）
            if(!KiteStringUtils.equals(kiteInst.getAttrValue("210004221"),"110007227")){
                LocalAttrHelper.hideAndNullable(kiteInst,
                    //不显示 突发带宽属性、突发周期属性、突发开始时间属性、突发结束时间
                    "210004191", "200001824", "210004306", "210004307");
                // 显示 VC捆绑方式属性、VC捆绑数量属性
                AttrModifyHelper.displayAndNullable(kiteInst,"210004194", "210004195");

            }else {
                // 可变带宽
                AttrModifyHelper.displayAndNotNull(kiteInst,
                    "210004191", "200001824", "210004306", "210004307");
                LocalAttrHelper.hideAndNullable(kiteInst, "210004194", "210004195");
                UpdateAttrValueEvent updateAttrValueEvent = new UpdateAttrValueEvent(new SuddenCycleHandler(), attrData.getCustId(), attrData.getStaffId());
                updateAttrValueEvent.setInst(kiteInst);
                updateAttrValueEvent.setKiteAttr(kiteAttr);
                updateAttrValueEvent.setAttrData(attrData);
                applicationContext.publishEvent(updateAttrValueEvent);
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr kiteAttr, KiteInst kiteInst, AttrData attrData) {

    }
}
